<?php

namespace app\common\model;

use app\common\model\BaseModel;


class WorkLog extends BaseModel
{

    

    

    // 表名
    protected $name = 'work_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'worker_arrive_time_text',
        'patient_arrive_time_text',
        'diagnose_begin_time_text',
        'diagnose_end_time_text',
        'examine_text',
        'examine_time_text',
        'medicine_text',
        'medicine_time_text',
        'reexamine_text',
        'patient_leave_time_text',
        'patient_unhappy_text',
        'create_time_text'
    ];
    

    
    public function getExamineList()
    {
        return ['0' => __('Examine 0'), '1' => __('Examine 1')];
    }

    public function getMedicineList()
    {
        return ['0' => __('Medicine 0'), '1' => __('Medicine 1')];
    }

    public function getReexamineList()
    {
        return ['0' => __('Reexamine 0'), '1' => __('Reexamine 1')];
    }

    public function getPatientUnhappyList()
    {
        return ['0' => __('Patient_unhappy 0'), '1' => __('Patient_unhappy 1')];
    }


    public function getWorkerArriveTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['worker_arrive_time']) ? $data['worker_arrive_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPatientArriveTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['patient_arrive_time']) ? $data['patient_arrive_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getDiagnoseBeginTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['diagnose_begin_time']) ? $data['diagnose_begin_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getDiagnoseEndTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['diagnose_end_time']) ? $data['diagnose_end_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getExamineTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['examine']) ? $data['examine'] : '');
        $list = $this->getExamineList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getExamineTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['examine_time']) ? $data['examine_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getMedicineTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['medicine']) ? $data['medicine'] : '');
        $list = $this->getMedicineList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getMedicineTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['medicine_time']) ? $data['medicine_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReexamineTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['reexamine']) ? $data['reexamine'] : '');
        $list = $this->getReexamineList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPatientLeaveTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['patient_leave_time']) ? $data['patient_leave_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPatientUnhappyTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['patient_unhappy']) ? $data['patient_unhappy'] : '');
        $list = $this->getPatientUnhappyList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setWorkerArriveTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPatientArriveTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setDiagnoseBeginTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setDiagnoseEndTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setExamineTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setMedicineTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPatientLeaveTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function order()
    {
        return $this->belongsTo('Order', 'order_id', 'id')->joinType('LEFT');
    }


    public function user()
    {
        return $this->belongsTo('User', 'worker_id', 'id')->joinType('LEFT');
    }


    public function workerinfo()
    {
        return $this->belongsTo('WorkerInfo', 'worker_id', 'user_id')->joinType('LEFT');
    }


    public function servicebasic()
    {
        return $this->belongsTo('ServiceBasic', 'code', 'code')->joinType('LEFT');
    }
}
